<?php
// +----------------------------------------------------------------------
// | 07FLYSAAS [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2025-2035 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------

namespace app\plat\controller;
use think\db;
/**
 * 用户控制器
 */
class TenRole extends PlatBase
{
    /**
     * 列表
     */
    public function show()
    {
        return  $this->fetch('show');
    }
    /**
     * 列表json数据
     */
    public function show_json()
    {
        $where = [];
        if(!empty($this->param['keywords'])){
            $where['name|intro']=['like','%'.$this->param['keywords'].'%'];
        }
        $list =$this->logicTenRole->gettenRoleList($where)->toArray();
        return $list;
    }
    
    /**
     * 添加
     */
    public function add()
    {
        IS_POST && $this->jump($this->logicTenRole->tenRoleAdd($this->param));

        return $this->fetch('add');
    }
    
    /**
     * 编辑
     */
    public function edit()
    {
        
        IS_POST && $this->jump($this->logicTenRole->tenRoleEdit($this->param));

        $info = $this->logicTenRole->getTenRoleInfo(['id' => $this->param['id']]);
        
        $this->assign('info', $info);

        return $this->fetch('edit');
    }
    /**
     * 删除
     */
    public function del()
    {
        $this->jump($this->logicTenRole->authDel($this->param));
    }

    /**
     * 菜单授权
     */
    public function menuAuth()
    {
        IS_POST && $this->jump($this->logicTenRole->setRoleMenuAuth($this->param));

        //重新得到授权菜单
        $authMenuList = $this->logicTenRoleMenu->getRoleMenuList(TEN_USER_ID,TEN_TENANT_ID);

        // 转为树形结构
        $menu_tree = $this->logicPlatBase->getListTree($authMenuList);

        $info = $this->logicTenRole->getTenRoleInfo(['id' => $this->param['id']]);

        // 菜单转换为多选视图，支持无限级
        $menu_view = $this->logicTenMenu->menuTreeCheckboxView($menu_tree,'child',$info['ten_menu_ids']);

        $this->assign('list', $menu_view);

        $this->assign('id', $this->param['id']);

        return $this->fetch('menu_auth');
    }
}
